/**
 * Copyright (c) 2006 RiseSoft Co.,Ltd  
 * $Header$
 */
package cn.newtest.bi.collection.model;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.time.DateFormatUtils;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.GenericGenerator;

/**
 * 窗口填报期
 *
 * @author <a href="mailto: chenjian@risesoft.net">陈健</a>
 * @version $Revision$
 * 
 */
@Entity
@org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)
@Table(name="Rpt_ReportPeriod_Template")
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
public class ReportWindowPeriod implements Comparable<Object>, Serializable {
	
	private static final long serialVersionUID = 747852000772523136L;

	@Id
	@Column(name="ReportPeriod_Template_guid",length=38)
	@GenericGenerator(name="ReportWindowPeriod-assigned",strategy="assigned")
	private String guid;
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="Template_GUID")
	private Template template;
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="ReportPeriod_GUID")
	private ReportPeriod reportPeriod;
	
	@Temporal(TemporalType.TIMESTAMP)
	private Date unlockDate;
	
	@Temporal(TemporalType.TIMESTAMP)
	private Date lockDate;
	
	@Temporal(TemporalType.TIMESTAMP)
	private Date lateDate;
	
	@Temporal(TemporalType.TIMESTAMP)
	private Date urgeDate;
	
	@Basic
	private Boolean isOpen;
	
	@Transient
	public String getLateDateString(){
		if(lateDate!=null){
			String str = DateFormatUtils.format(lateDate, "yyyy-MM-dd HH:mm:ss");
			return str;
		}
		return null;
	}
	
	public Boolean getIsOpen() {
		return isOpen;
	}
	public void setIsOpen(Boolean isOpen) {
		this.isOpen = isOpen;
	}

	public String getGuid() {
		return guid;
	}

	public void setGuid(String guid) {
		this.guid = guid;
	}

	public Date getLateDate() {
		return lateDate;
	}

	public void setLateDate(Date lateDate) {
		this.lateDate = lateDate;
	}

	public Date getLockDate() {
		return lockDate;
	}

	public void setLockDate(Date lockDate) {
		this.lockDate = lockDate;
	}

	public ReportPeriod getReportPeriod() {
		return reportPeriod;
	}

	public void setReportPeriod(ReportPeriod reportPeriod) {
		this.reportPeriod = reportPeriod;
	}

	public Template getTemplate() {
		return template;
	}

	public void setTemplate(Template template) {
		this.template = template;
	}
	
	/**
	 * @return 从模板对象返回GUID
	 */
	@Transient
	public String getTemplateGuid() {
		if (template != null) {
			return template.getGuid();
		}
		return "";
	}
	public void setTemplateGuid(String templateGuid) {
		if (templateGuid != null && templateGuid.trim().length() > 0) {
			if (template == null) {
				template = new Template();
			}
			template.setGuid(templateGuid);
		}
	}
	
	/**
	 * @return 从模板对象返回code
	 */
	@Transient
	public String getTemplateCode() {
		return template.getCode();
	}
	
	/**
	 * @return 从报告期实例返回GUID
	 */
	@Transient
	public String getReportPeriodGuid() {
		if (reportPeriod != null) {
			return reportPeriod.getGuid();
		}
		return "";
	}
	public void setReportPeriodGuid(String reportPeriodGuid) {
		if (reportPeriodGuid != null && reportPeriodGuid.trim().length() > 0) {
			if (reportPeriod == null) {
				reportPeriod = new ReportPeriod();
			}
			reportPeriod.setGuid(reportPeriodGuid);
		}
	}
	
	/**
	 * @return 从报告期实例返回CODE
	 */
	@Transient
	public String getReportPeriodCode() {
		return reportPeriod.getCode();
	}
	
	/**
	 * @return 从报告期实例返回name
	 */
	@Transient
	public String getReportPeriodName() {
		return reportPeriod.getName();
	}
	
	public Date getUnlockDate() {
		return unlockDate;
	}

	public void setUnlockDate(Date unlockDate) {
		this.unlockDate = unlockDate;
	}

	public Date getUrgeDate() {
		return urgeDate;
	}

	public void setUrgeDate(Date urgeDate) {
		this.urgeDate = urgeDate;
	}

	/**
	 * @see java.lang.Comparable#compareTo(Object)
	 */
	public int compareTo(Object object) {
		ReportWindowPeriod myClass = (ReportWindowPeriod) object;
		return new CompareToBuilder().append(this.lockDate, myClass.lockDate).append(this.unlockDate, myClass.unlockDate).append(this.urgeDate, myClass.urgeDate).append(this.guid, myClass.guid)
				.append(this.lateDate, myClass.lateDate).toComparison();
	}

	/**
	 * @see java.lang.Object#equals(Object)
	 */
	public boolean equals(Object object) {
		if (!(object instanceof ReportWindowPeriod)) {
			return false;
		}
		ReportWindowPeriod rhs = (ReportWindowPeriod) object;
		return new EqualsBuilder().appendSuper(super.equals(object)).append(this.lockDate, rhs.lockDate).append(this.unlockDate, rhs.unlockDate).append(this.urgeDate, rhs.urgeDate).append(this.guid, rhs.guid).append(this.lateDate, rhs.lateDate).isEquals();
	}

	/**
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
		return new HashCodeBuilder(338467891, -1143363385).appendSuper(super.hashCode()).append(this.lockDate).append(this.unlockDate).append(this.urgeDate).append(this.guid).append(this.lateDate).toHashCode();
	}

	/**
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return new ToStringBuilder(this).append("unlockDate", this.unlockDate).append("lockDate", this.lockDate).append("lateDate", this.lateDate).append("guid", this.guid).append("urgeDate", this.urgeDate)
				.toString();
	}

}